package com.gpt.article.service.impl.taskHandle;

import chatgpt.ChatGPT;
import com.gpt.article.domain.GptTopicTitle;
import com.gpt.article.domain.TxtClassify;
import com.gpt.article.service.impl.taskHandle.task.XiGaoTasker;
import com.ruoyi.common.config.RuoYiConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

public class GenTxtClassifyTask extends GenTask{
    private static Logger logger = LoggerFactory.getLogger(GenTxtClassifyTask.class);
    private Long taskId;
    private ChatGPT chatGPT;
    private GenTask xigaoTask;


    /**
     * 根据要求生成内容分类任务创建
     * @param taskId
     * @param acc
     * @param txtClassifies
     * @return
     */
    public Integer createContentClassifyTask(Long taskId, String acc , List<TxtClassify> txtClassifies, Map<String,Object> map){
        this.taskId = taskId;
        int genNum = txtClassifies.size();
        try {
            chatGPT = ChatGPT.builder()
                    .apiKey(RuoYiConfig.getApiKeys())
                    .timeout(9000)
//                .proxy(proxy)
                    .apiHost(RuoYiConfig.getGptApiHost()) //代理地址
                    .build()
                    .init();
        }catch (Exception e){
            logger.error("丢包或者请求异常重试:{}",e.getMessage());
        }
        chatGPT = new GptRequstHelper().getGpt(chatGPT);
        xigaoTask = new GenTask.Builder()
                .setTaskNum(genNum)
                .setAcc(acc)
                .setThreadCount(Integer.valueOf(RuoYiConfig.getGenThreadCount()))
                .setGenType("txtClassifies")
//                .setGptFunPrompts(gptFunPrompts)
//                .setRefer(refer)
//                .addArticleList(articles)
                .setchatGpt(chatGPT)
//                .setOneToNum(oneToNum)
//                .setUseModel(ChatCompletion.Model.GPT_3_5_TURBO_0613.getName())
                .addTxtClassifiesTask(txtClassifies)
                .addPsMap(map)
//                .setTxtlength(txtlength)
//                .setTuswitch(tuswitch)
//                .setXituSwitch(xituSwitch)
                .build();
        xigaoTask.start(true,"txtClassifies");
//        logger.info("文案创建任务结束：{}");
        new XiGaoTasker().upTask(taskId,0,0,genNum,"2");
        return genNum;

    }


}
